package transaction_date

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 持有一段时间的卖出日
type HoldTimeSellDate struct {
	db *gorm.DB
}

// 初始化
func (h *HoldTimeSellDate) Init(db *gorm.DB) {
	h.db = db
}

// 是否是卖出日
func (h *HoldTimeSellDate) IsSellDate(transactionDate string) bool {
	var origin int = 0
	var stockNumber *int = &origin
	h.db.Raw("select count(distinct t.date_) from quant_account_log t where t.date_<to_date(?,'yyyy-mm-dd')", transactionDate).Scan(&stockNumber)
	if (*stockNumber+properties.QuantProperties_.HoldTime-1)%properties.QuantProperties_.HoldTime == 0 {
		io.Infoln("日期[%s]是卖出日", transactionDate)
		return true
	} else {
		//if transactionDate == properties.QuantProperties_.RealtimeBeginDate {
		//	return true
		//} else {
		//	return false
		//}
		return false
	}
}
